package com.wyt.common.reptile;

import com.alibaba.fastjson.JSON;
import org.apache.commons.compress.utils.CharsetNames;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ReptileTableName
 * @Description: TODO
 * @Author wangyongtao
 * @Date 2021/9/15 19:26
 * @Version 1.0
 **/
public class ReptileTableName {


    public static void parseHtml(List<String> list) throws IOException {
        //1、获取页面文档数据
        Document doc = Jsoup.parse(new File("E:\\IdeaProjects\\wyt01utils\\wyt01-common\\src\\main\\java\\com\\wyt\\common\\reptile\\hbase.html"), CharsetNames.UTF_8);
        //2、获取页面上所有的tbody标签
        Elements elements = doc.getElementsByTag("tbody");
        //3、拿到第1个tbody标签
        Element element = elements.get(0);
        //4、拿到tbody标签下所有的子标签
        Elements childrens = element.getElementsByTag("tr");

        for (int i=1;i<childrens.size();i++){
            Element tr = childrens.get(i);
            Element td = tr.getElementsByTag("td").get(0);
            String tableName = td.getElementsByTag("a").text();
            if (tableName.startsWith("KYLIN")){
                list.add(tableName);
            }
        }
    }

    public static void main(String[] args) throws Exception{
        List<String> list = new ArrayList<>();
        parseHtml(list);
        list.forEach(System.out::println);

    }

}
